package com.jinlejia.erp.utils;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

import com.jinlejia.erp.R;


/**
 * Created by Administrator on 2017/9/27 0027.
 */

public class LeftLineDecoration extends RecyclerView.ItemDecoration {
    private int tagWidth;
    private int outWidth;
    private Paint leftPaint;
    private Paint rightPaint;
    private float last;
    private Context context;

    public LeftLineDecoration(Context context) {
        this.context = context;
        leftPaint = new Paint();
//        rightPaint = new Paint();
//        rightPaint.setColor(context.getResources().getColor(R.color.menu_orange));
        tagWidth = context.getResources().getDimensionPixelSize(R.dimen.tag_width);
        outWidth = context.getResources().getDimensionPixelSize(R.dimen.out_width);
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        outRect.left = outWidth;
    }

    @Override
    public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
        super.onDrawOver(c, parent, state);
        int childCount = parent.getChildCount();
        if (childCount != 2 && childCount>0){
            last = parent.getChildAt(childCount-1).getBottom();
        }
        if (childCount > 0){
            for (int i = 0; i < childCount; i++) {
                if (i == 0 ){
                    leftPaint.setColor(context.getResources().getColor(R.color.yellow));
                }else {
                    leftPaint.setColor(context.getResources().getColor(R.color.colorDivider));
                }
                View child = parent.getChildAt(i);
                float left = child.getLeft()+ DisplayUtil.dip2px(context,22.0f);
                float right = left + tagWidth;
                float top = child.getTop()+DisplayUtil.dip2px(context,25.0f);
                float bottom = child.getBottom()+DisplayUtil.dip2px(context,-3.0f);
                if (i == childCount-1){//去掉footView 的左边线
                    return;
                }
                c.drawRect(left, top, right, bottom, leftPaint);
            }
        }
    }
}
